/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.rcnss.ui.form;

import com.rcnss.data.ITable;
import com.rcnss.data.Reclamation;
import com.vaadin.event.ItemClickEvent;
import com.vaadin.event.ItemClickEvent.ItemClickListener;
import com.vaadin.ui.Label;
import com.vaadin.ui.Panel;
import com.vaadin.ui.SplitPanel;
import com.vaadin.ui.Tree;
import java.util.ArrayList;

/**
 *
 * @author Baligh GUESMI
 */
public class AppForm extends AbstractForm{
    
    private static final long serialVersionUID = 1L;
    private Tree reclamationTree = new Tree();

    private Label title = new Label("sdfsdfsdf");

    public AppForm()
    {
        initLayout();
        initTree();
    }
    
    public void initTree()
    {
    	Panel panel = new Panel();
    	panel.setSizeFull();
        ArrayList<Reclamation> rec = Reclamation.SearchByNom("Test");
        if(rec.isEmpty())
            this.reclamationTree.addItem("Empty");
        else
            for (Reclamation r : rec) {
                this.reclamationTree.addItem(r);
                this.reclamationTree.addListener(new ItemClickListener() {

                public void itemClick(ItemClickEvent event) {
                    EditForm f = new EditForm((ITable)event.getItem(), null);
                    splitPanel.addComponent(f);
                }
            });
            }
    	panel.addComponent(this.reclamationTree);
    	this.splitPanel.addComponent(panel);
        this.splitPanel.setSplitPosition(20, SplitPanel.UNITS_PERCENTAGE);
    }

    public void setTitle(String text)
    {
        this.title.setValue(text);
    }
    
}
